package com.igd.business.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.igd.business.dao.IResDao;
import com.igd.business.service.IResService;
import com.igd.common.constant.IConstant;
import com.igd.exceptions.IgdException;
import com.igd.pojo.vo.PageList;
import com.igd.security.Resources;
import com.igd.security.User;
import com.igd.utils.CommonUtil;
import com.igd.utils.DateUtil;

/**
 * @version 1.0
 * 
 * @author QIAOYU
 * 
 * @date 2013-7-5
 * 
 * @description 平台资源信息服务实现类
 */

public class IResServiceImpl implements IResService {

	private IResDao resDao;

	public Resources saveResources(Resources res) throws SQLException,IgdException {
		
		if(null != res){
			
			User user = (User) CommonUtil.getCurrentUser();
			
			if(null != user){
				
				res.setResCreateUser(user.getUserId());

				res.setResStatus(IConstant.RESOURCES_PROHIBIT_STATUS);
				
				res.setResCreateTime(DateUtil.getLongDate());
				
				this.getResDao().insertResources(res);
				
				return res;
			}
		}
		
		return null;
	}

	public List<Resources> getAllRes(PageList pageList) throws SQLException,IgdException {

		return this.getResDao().queryAllRes(pageList, new Resources());
	}

	public void delResources(Resources res) throws SQLException, IgdException {

		this.getResDao().deleteResources(res);

	}

	public Resources getResInfoByResId(String resId) throws SQLException,IgdException {

		if (StringUtils.isNotEmpty(resId)) {

			Resources res = new Resources();

			res.setResId(resId);

			return this.getResDao().queryResInfo(res);

		}

		return null;
	}

	public void updateResourcesByResId(Resources res) throws SQLException,IgdException {
		
		if(StringUtils.isNotEmpty(res.getResId())){
			
			this.getResDao().updResources(res);

		}
	}
	
	public IResDao getResDao() {
		return resDao;
	}

	public void setResDao(IResDao resDao) {
		this.resDao = resDao;
	}
}
